package javaWeek14;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.sql.Statement;

public class Main {
	
    public static void displayAll(){
    	String URL = "jdbc:mysql://localhost:3306/test";
		String driverName = "com.mysql.jdbc.Driver";
		String sql = "select stuno,name,birthdate from students";
		String userName = "root";//root
		String password = "root";//root
		Connection conn = null;
					
		try {
			conn = DriverManager.getConnection(URL,userName,password);
			Statement statement = conn.createStatement();
			ResultSet resultSet = statement.executeQuery(sql);
			Class.forName(driverName);
			while(resultSet.next()){
				String name=resultSet.getString("name");
				String stuno = resultSet.getString("stuno");
				Date date = resultSet.getDate("birthdate");
				System.out.print(" stuno="+stuno+" name="+name+"  birthdate="+date);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}finally{
			if(conn!=null)
				try {
					conn.close();
				} catch (SQLException e) {

					e.printStackTrace();
				}
			conn = null;
		}
    }

	public static void main(String[] args) {
		displayAll();
	}

}